<template>
  <div class="box">
    <div class="rich_media_title">{{ title }}</div>
    <div class="publish_time"> {{ push_date }}</div>
    <div class="content_style" v-html="content"></div>
  </div>
</template>

<script>
import { reactive, toRefs, defineComponent, onMounted } from "vue";
import { useRoute, useRouter } from "vue-router";
import request from "../../../common/utils/request";
import utils from "../../../common/utils/utils";
export default defineComponent({
  name: "TextPreview",
  setup() {
    const route = useRoute();
    const router = useRouter();

    const state = reactive({
      count: 0,
      content: "",
      updatedAt: "",
      title: "",
      push_date:""
    });

    // 轮播图
    const getBannerDetail = (id) => {
      request.get("/work_ai", "/user/shotstack/banner/detail", { id }).then((res) => {
        state.content = res.result.content;
        state.updatedAt = res.result.updated_at;
        state.title = res.result.title;
        state.push_date =  res.result?.push_date;
        utils.setDocumentTitle(state.title);
      });
    };

    // 公告
    const getNoticeList = (id) => {
      request.get("/work_ai", "/user/shotstack/notice/detail", { id }).then((res) => {
        state.content = res.result.content;
        state.updatedAt = res.result.updated_at;
        state.title = res.result.title;
        state.push_date =  res.result?.push_date;
        utils.setDocumentTitle(state.title);
      });
    };

    // 课程
    const getCourseDetail = (id) => {
      request.get("/work_ai", "/user/shotstack/course/detail", { id }).then((res) => {
        state.content = res.result.content;
        state.updatedAt = res.result.updated_at;
        state.title = res.result.title;
        state.push_date =  res.result?.push_date;
        utils.setDocumentTitle(state.title);
      });
    };

    onMounted(() => {
      // 轮播图详情
      if (route.query.type == "banner") {
        getBannerDetail(Number(route.query.id));
      }

      // 公告详情
      if (route.query.type == "notice") {
        getNoticeList(Number(route.query.id));
      }
      // 课程详情
      if (route.query.type == "course") {
        getCourseDetail(Number(route.query.id));
      }
    });

    return {
      ...toRefs(state),
    };
  },
});
</script>

<style lang="less" scoped>
.box {
  max-width: 677px;
  padding-top: 20px;
  margin: 0 auto;
  .rich_media_title {
    font-size: 22px;
    line-height: 1.4;
    margin-bottom: 14px;
  }
  .publish_time {
    color: #999;
    margin-bottom: 10px;
  }
  .content_style{
    font-size: 15px;

    :deep(img){
      width: 100%;
      height: auto;
    }
  }
}
</style>
